/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package b_and_b_properties;

import b_and_b_properties.data.DAO;
import b_and_b_properties.data.Property;
import b_and_b_properties.data.Unit;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

/**
 *
 * @author Student
 */
public class PropertyEntry extends JPanel {

    /** Create text fields.
     * Create labels and ComboBoxes.
     * Create Radio buttons.
     */
    private Property prop;
    private Unit unitObject;
    private DAO daoObject;
    private JLabel jlCounty;
    private JTextField jtfCounty;
    private JLabel jlTaxID;
    private JTextField jtfTaxID;
    private JCheckBox jcbSingleFam;
    private JCheckBox jcbApartment;
    private JComboBox jcbPropertySubType;
    private JLabel jlStreetNum;
    private JTextField jtfStreetNum;
    private JLabel jlStreetName;
    private JTextField jtfStreetName;
    private JComboBox jcbPostDir;
    private JComboBox jcbSuffix;
    private JLabel jlUnit;
    private JTextField jtfUnit;
    private JLabel jlCity;
    private JTextField jtfCity;
    private JLabel jlZipCode;
    private JTextField jtfZipCode;
    private JLabel jlCrossStreet;
    private JTextField jtfCrossStreet;
    private JLabel jlShowingInstr;
    private JTextField jtfShowingInstr;
    private JLabel jlPublicTrans;
    private JTextField jtfPublicTrans;
    private JLabel jlLeaseAmount;
    private JTextField jtfLeaseAmount;
    private JLabel jlLeaseDate;
    private JTextField jtfLeaseDate;
    private JComboBox jcbSecurityDeposit;
    private JComboBox jcbPetAllowed;
    private JComboBox jcbPetRestriction;
    private JComboBox jcbExtraPetDeposit;
    private JLabel jbForSale;
    private JRadioButton jrbForSale;
    private JRadioButton jrbSale;
    private JTextField jtfPrice;
    private JLabel jlNumberOfUnits;
    private JTextField jtfNumberOfUnits;
    private JButton jSave;
    private JButton jDelete;
    

    
    /**
     * Creates the Property Object.
     */
    public PropertyEntry(final DAO daoObject, Property property) {
        this.daoObject = daoObject;       
         
        
        /**
         * Create panels to size and location.
         */
        JPanel p1 = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 30));
        JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 30));
        JPanel p3 = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 30));
        JPanel p4 = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 30));
        JPanel p5 = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 30));
        JPanel p6 = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 30));
        JPanel p7 = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 30));
        JPanel p8 = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 30));
        JPanel p9 = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 30));
        JPanel p10 = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 30));
        
        /**
         * Set the Lay out of the panel.
         */
        setLayout(new GridLayout(10, 6, 5, 7));


        jSave.setBounds(10, 10, 50,40);
        jDelete.setBounds(10, 10, 50, 40);
        

        /**
         * Adds two buttons to a option.
         */
        ButtonGroup group = new ButtonGroup();

        group.add(jrbSale);
        group.add(jrbForSale);
        
        group.add(jSave);
        group.add(jDelete);
        
        
        /**
         * Adding the panel.
         * Sets the number of columns in the text field
         * and invalidates the layout.
         */
        p1.add(jlCounty);
        jtfCounty.setColumns(25);
        p1.add(jtfCounty);
        jtfTaxID.setColumns(30);
        p1.add(jlTaxID);
        p1.add(jtfTaxID);
        
        jtfNumberOfUnits.setColumns(5);
        p2.add(jlNumberOfUnits);
        p2.add(jtfNumberOfUnits);
        p2.add(jcbPropertySubType);
        p2.add(jcbSingleFam);
        p2.add(jcbApartment);

        jtfStreetNum.setColumns(20);
        p3.add(jlStreetNum);
        p3.add(jtfStreetNum);
        jtfStreetName.setColumns(10);
        p3.add(jlStreetName);
        p3.add(jtfStreetName);
        p3.add(jcbSuffix);
        p3.add(jcbPostDir);
        jtfUnit.setColumns(10);
        p3.add(jlUnit);
        p3.add(jtfUnit);

        jtfCity.setColumns(20);
        p4.add(jlCity);
        p4.add(jtfCity);
        jtfZipCode.setColumns(40);
        p4.add(jlZipCode);
        p4.add(jtfZipCode);

        jtfCrossStreet.setColumns(60);
        p5.add(jlCrossStreet);
        p5.add(jtfCrossStreet);

        jtfShowingInstr.setColumns(90);
        p6.add(jlShowingInstr);
        p6.add(jtfShowingInstr);

        jtfPublicTrans.setColumns(40);
        p7.add(jlPublicTrans);
        p7.add(jtfPublicTrans);

        jtfLeaseAmount.setColumns(10);
        p8.add(jlLeaseAmount);
        p8.add(jtfLeaseAmount);
        jtfLeaseDate.setColumns(10);
        p8.add(jlLeaseDate);
        p8.add(jtfLeaseDate);

        p8.add(jcbSecurityDeposit);
        p8.add(jcbSecurityDeposit);

        p9.add(jcbPetAllowed);
        p9.add(jcbPetRestriction);
        p9.add(jcbExtraPetDeposit);
        p9.add(jbForSale);
        p9.add(jrbForSale);
        p9.add(jrbSale);
        jtfPrice.setColumns(10);
        p9.add(jtfPrice);
        
        p10.add(jSave);
        p10.add(jDelete);
        
        jtfPrice.setEnabled(false);
        jcbPetAllowed.setEnabled(true);
        
        jSave.setEnabled(true);
        jDelete.setEnabled(true);
        

        /**
         * Adds panels to the frame.
         */
        add(p1);
        add(p2);
        add(p3);
        add(p4);
        add(p5);
        add(p6);
        add(p7);
        add(p8);
        add(p9);
        add(p10);


        /**
         * Adds Action Listener to a radio button when checked.
         */

        jrbForSale.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jtfPrice.setEnabled(true);
                repaint();
            }
        });


        jrbSale.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jtfPrice.setEnabled(false);
                repaint();
            }
        });

        /**
         * Adding listeners to the text fields.
         */
        jtfCounty.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
//                daoObject.getPropertyCountyField().setText(jtfCounty.getText());

            }
        });

        jtfTaxID.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
//                daoObject.getPropertyTaxIDField().setText(jtfTaxID.getText());
            }
        });

        jtfStreetNum.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
//                daoObject.getPropertyStreetNumberField().setText(jtfStreetNum.getText());
            }
        });

        jtfStreetName.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
//                daoObject.getPropertyStreetNameField().setText(jtfStreetName.getText());
            }
        });

        jtfUnit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
//                daoObject.getUnitListDateField().setText(jtfUnit.getText());
            }
        });

        jtfCity.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
//                daoObject.getPropertyCityField().setText(jtfCity.getText());
            }
        });

        jtfZipCode.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
//                daoObject.getPropertyZipCodeField().setText(jtfZipCode.getText());
            }
        });

        jtfCrossStreet.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
//                daoObject.getPropertyCrossStreetField().setText(jtfCrossStreet.getText());
            }
        });

        jtfShowingInstr.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                //daoObject.getPropertyShowingInstrField().setText(jtfShowingInstr.getText()):
            }
        });
        
        
        jtfLeaseAmount.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
               //daoObject.getPropertyLeaseAmountField().setText(jtfLeaseAmount.getText());
            }
        });
        
        jtfLeaseDate.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
               //daoObject.getPropertyLeaseDateField().setText(jtfLeaseDate.getText());
            }
        });
        
        /**
         * Adds listeners to combo boxes.
         */
        jcbPropertySubType.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jcbPropertySubType.setMaximumRowCount(4);
                jcbPropertySubType.setEditable(false);
            }
        });
        
        jcbPostDir.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jcbPostDir.setMaximumRowCount(5);
                jcbPostDir.setEditable(false);
            }
        });
        
        jcbSuffix.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jcbSuffix.setMaximumRowCount(6);
                jcbSuffix.setEditable(false);
            }
        });
        
        jcbSecurityDeposit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jcbSecurityDeposit.setMaximumRowCount(4);
                jcbSecurityDeposit.setEditable(false);
            }
        });
        
        jcbPetAllowed.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jcbPetAllowed.setMaximumRowCount(3);
                jcbPetAllowed.setEditable(false);
            }
        });
        
        jcbPetRestriction.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if(jcbPetRestriction.getSelectedIndex() == 0){
                    
                }
                //jcbPetRestriction.setMaximumRowCount(3);
                //jcbPetRestriction.setEditable(false);
            }
        });
        
        jcbExtraPetDeposit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jcbExtraPetDeposit.setMaximumRowCount(3);
                jcbExtraPetDeposit.setEditable(false);
            }
        });
        
        /**
         * Adding listeners to save and delete button.
         */      
        jSave.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jSave.setForeground(Color.RED);
            }
        });
        
        jDelete.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jDelete.setForeground(Color.BLUE);
            }
        });
    }

    
    /**
     * Adding the variables to library.
     */

    private void initComponents(){
        jlCounty = new JLabel("County");
        jtfCounty = new JTextField(25);
        jlTaxID = new JLabel("Tax ID");
        jtfTaxID = new JTextField(30);
        jlNumberOfUnits = new JLabel("Number Of Units");
        jtfNumberOfUnits = new JTextField(5);
        jcbSingleFam = new JCheckBox("Single Family");
        jcbApartment = new JCheckBox("Apartment");
        jcbPropertySubType = new JComboBox(new String[]{"Property Sub-Type",
            "Duplex", "Triplex", "Quad"
            });
        jlStreetNum = new JLabel("Street Number");
        jtfStreetNum = new JTextField(20);
        jlStreetName = new JLabel("Street Name");
        jtfStreetName = new JTextField(10);
        jcbPostDir = new JComboBox(new String[]{"Post Direction", "North",
                "South", "East", "West"
            });
        jcbSuffix = new JComboBox(new String[]{"Suffix", "Drive", "Road", "Street",
                "Avenue", "Court"
            });
        jlUnit = new JLabel("Unit Number");
        jtfUnit = new JTextField(10);
        jlCity = new JLabel("City/Municipality:");
        jtfCity = new JTextField(20);
        jlZipCode = new JLabel("ZipCode");
        jtfZipCode = new JTextField(40);
        jlCrossStreet = new JLabel("Cross Street");
        jtfCrossStreet = new JTextField(60);
        jlShowingInstr = new JLabel("Showing Instruction");
        jtfShowingInstr = new JTextField(90);
        jlPublicTrans = new JLabel("Public Transportation");
        jtfPublicTrans = new JTextField(40);
        jlLeaseAmount = new JLabel("Lease Amount");
        jtfLeaseAmount = new JTextField(10);
        jlLeaseDate = new JLabel("Date Of Lease");
        jtfLeaseDate = new JTextField(10);
        jcbSecurityDeposit = new JComboBox(new String[]{"Security Deposit",
                "Yes", "No", "One Months Rent"
            });
        jcbPetAllowed = new JComboBox(new String[]{"Pets Allowed", "Yes", "No"});
        jcbPetRestriction = new JComboBox(new String[]{"Pet Restrictions", "Yes", "No"});
        jcbExtraPetDeposit = new JComboBox(new String[]{"Extra Pet Deposit",
                "Yes", "No"
            });
        jbForSale = new JLabel("Option to buy House");
        jrbForSale = new JRadioButton("Yes");
        jrbSale = new JRadioButton("No");
        jtfPrice = new JTextField(10);
        jSave = new JButton("Save Record");
        jDelete = new JButton("Delete Record");
    }
    

   public PropertyEntry(DAO daoObject, Unit unitObject ){
        initComponents();
        loadProperty();
        saveProperty();
        loadUnit();
        saveUnit();
        this.daoObject = daoObject;
        this.unitObject = unitObject;
        
   }
    private void loadProperty() {
//        daoObject.getPropertyCountyField().setText(jtfCounty.getText());
//        daoObject.getPropertyTaxIDField().setText(jtfTaxID.getText());
//        daoObject.getPropertySubdivisionField().setText(
//                jcbPropertySubType.getSelectedItem().toString());     
//        daoObject.getPropertyStreetNumberField().setText(jtfStreetNum.getText());
//        daoObject.getPropertyStreetNameField().setText(jtfStreetName.getText());
//        daoObject.getPropertyStreetSuffixField().setText(
//                jcbSuffix.getSelectedItem().toString());
//        daoObject.getPropertyCityField().setText(jtfCity.getText());
//        daoObject.getPropertyZipCodeField().setText(jtfZipCode.getText());
//        daoObject.getPropertyCrossStreetField().setText(jtfCrossStreet.getText());
//        //daoObject.getPropertyShowingInstructionField().setText(jtfShowingInstr.getText());
//        daoObject.getPropertyPetDepositField().setText(
//                jcbExtraPetDeposit.getSelectedItem().toString());
//        daoObject.getPropertyPetsAllowedField().setText(
//                jcbPetAllowed.getSelectedItem().toString());
//        daoObject.getPropertyPetRestrictionsField().setText(
//                jcbPetRestriction.getSelectedItem().toString());
        
    }
    private void saveProperty() {
//        jtfCounty.setText(daoObject.getPropertyCountyField().getText());
//        jtfTaxID.setText(daoObject.getPropertyTaxIDField().getText());
//        jcbPropertySubType.setSelectedItem(
//                daoObject.getPropertySubdivisionField().getText().toString());
//        jtfStreetNum.setText(daoObject.getPropertyStreetNumberField().getText());
//        jtfStreetName.setText(daoObject.getPropertyStreetNameField().getText());
//        jcbSuffix.setSelectedItem(
//                daoObject.getPropertyStreetSuffixField().getText().toString());
//        jtfCity.setText(daoObject.getPropertyCityField().getText());
//        jtfZipCode.setText(daoObject.getPropertyZipCodeField().getText());     
//        //jtfShowingInstr.setText(daoObject.getPropertyShowingInstrField().getText()); 
//        jtfCrossStreet.setText(daoObject.getPropertyCrossStreetField().getText());  
//        jcbExtraPetDeposit.setSelectedItem(
//                daoObject.getPropertyPetDepositAmountField().getText().toString());
//        jcbPetAllowed.setSelectedItem(
//                daoObject.getPropertyPetsAllowedField().getText().toString());
//        jcbPetRestriction.setSelectedItem(
//                daoObject.getPropertyPetRestrictionsField().getText().toString());
//        //jtfPrice.setText(daoObject.getPropertyPriceField().getText());
    }
    
   
    
    private void loadUnit(){
        
    }
    
    private void saveUnit(){
    }
    
  
}